﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using IChessEngine;

namespace ChessControls
{
    /// <summary>
    /// Interaction logic for ChsPieceControl.xaml
    /// </summary>
    public partial class ChsPieceControl : UserControl
    {
        private IChsPiece piece = null;
        private IChsSquare square = null;
        public ChsPieceControl()
        {
            InitializeComponent();
        }
        public IChsPiece Piece
        {
            get
            {
                return piece;
            }
            set
            {
                piece = value;
                RefreshControl();
            }
        }
        public IChsSquare Square
        {
            get
            {
                return square;
            }
            set
            {
                square = value;
            }
        }
        private void RefreshControl()
        {
            if (piece == null)
                ImgPiece.Source = null;
            else
                ImgPiece.Source =
                            new BitmapImage(
                                new Uri(String.Format("pack://application:,,,/ChessControls;component/Images/{0}_{1}.PNG",piece.Color,piece.Type)));
        }
        private void ImgPiece_MouseDown(object sender, MouseButtonEventArgs e)
        {
            DataObject dataObject = new DataObject();
            dataObject.SetData("ChsPiece", piece);
            dataObject.SetData("ChsSquare", square);
            DragDrop.DoDragDrop(this, dataObject, DragDropEffects.Move);
        }

        private void ImgPiece_PreviewDrop(object sender, DragEventArgs e)
        {

        }
    }
}
